<template>
    <div class="enroll px-20">
        <div v-if="isOpen" class="pt-15">
            <form-view
                :list="formMember"
                :gridFormItem="4"
                :height="0"
                row
            ></form-view>
        </div>
        <div class="fr-ac-jsb pb-15" :class="isOpen ? '' : 'pt-15'">
            <el-button :style="purple" @click="enterExport(enrolCondition)">
                导出
            </el-button>
            <el-button @click="isOpen = !isOpen">
                <el-icon>
                    <Search />
                </el-icon>
            </el-button>
        </div>
        <table-view
            :data="tableData"
            :propList="tableProp"
            :total="tableTotal"
            :pageSize="15"
            @pageClick="tablePage"
            :spacing="20"
        ></table-view>
    </div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { enrollLists, enrollExport } from "./volunteer";
import { useUserStore } from "@/store/userStore";
import { red, blue, purple, purpleWhite } from "@/comment/data";
import {
    updateMessage,
    time,
    updateOrGetValue,
    optionsArray,
    flieDownload,
} from "@/comment/method";
import { zxkm, sxkm, sex, year, getYear } from "./data";
const userStore = useUserStore();
const tableData = ref([]);
const tableProp = ref([
    {
        id: 1,
        prop: "id",
        label: "ID",
    },
    {
        id: 2,
        prop: "phone",
        label: "手机号",
    },
    {
        id: 3,
        prop: "year",
        label: "年份",
    },
    {
        id: 4,
        prop: "ksxx_name",
        label: "考生姓名",
    },
    {
        id: 5,
        prop: "xk",
        label: "选科",
    },
    {
        id: 6,
        prop: "score",
        label: "分数",
    },
    {
        id: 7,
        prop: "ksxx_sex",
        label: "考生性别",
    },
    {
        id: 8,
        prop: "schoolMajor",
        label: "院校/专业",
    },
    {
        id: 9,
        prop: "create_time",
        label: "时间",
    },
]);
const tableTotal = ref(0);
const enrolCondition = ref({
    ksxx_name: "",
    phone: "",
    ksxx_sxkm: "",
    ksxx_zxkm: "",
    min_score: "",
    max_score: "",
    ksxx_sex: "",
    year: getYear,
});
const isOpen = ref(false);
const formMember = ref([
    {
        id: 1,
        prefix: false,
        type: "",
        label: "姓名",
        model: "",
        prop: "ksxx_name",
        suffixIcon: "",
        rules: [],
        formType: "input",
        placeholder: "请输入姓名",
        list: [],
    },
    {
        id: 2,
        prefix: false,
        type: "",
        label: "手机号",
        model: "",
        prop: "phone",
        suffixIcon: "",
        rules: [],
        formType: "input",
        placeholder: "请输入手机号",
        list: [],
    },
    {
        id: 3,
        prefix: false,
        type: "",
        label: "性别",
        model: "",
        prop: "ksxx_sex",
        suffixIcon: "CaretBottom",
        rules: [],
        formType: "select",
        placeholder: "请选择",
        list: optionsArray(sex, "", "", "请选择"),
    },
    {
        id: 4,
        prefix: false,
        type: "",
        label: "首选",
        model: "",
        prop: "ksxx_sxkm",
        suffixIcon: "CaretBottom",
        rules: [],
        formType: "select",
        placeholder: "请选择",
        list: optionsArray(sxkm, "", "", "请选择"),
    },
    {
        id: 5,
        prefix: false,
        type: "",
        label: "再选",
        model: "",
        prop: "ksxx_zxkm",
        suffixIcon: "CaretBottom",
        rules: [],
        formType: "select",
        placeholder: "请选择",
        list: optionsArray(zxkm, "", "", "请选择"),
    },
    {
        id: 6,
        prefix: false,
        type: "",
        label: "分数",
        model: "",
        prop: "score",
        suffixIcon: "",
        rules: [],
        formType: "col",
        placeholder: "请选择",
        list: [],
    },
    {
        id: 7,
        prefix: false,
        type: "",
        label: "年份",
        model: getYear,
        prop: "year",
        suffixIcon: "CaretBottom",
        rules: [],
        formType: "select",
        placeholder: "请选择",
        list: optionsArray(year),
    },
    {
        id: 8,
        prefix: false,
        type: "",
        label: "",
        model: "",
        prop: "",
        suffixIcon: "",
        rules: [],
        formType: "null",
        placeholder: "",
        list: [
            {
                label: "查询",
                value: "查询",
                type: "query",
                style: purple,
                void: (val) => {
                    enrolCondition.value = val;
                    list(val);
                },
            },
            {
                label: "重置",
                value: "重置",
                type: "reset",
                style: purpleWhite,
                void: (val) => {
                    enrolCondition.value = val;
                    list(val);
                },
            },
        ],
    },
]);
const list = async (condition, page = 1) => {
    let data = {
        ...condition,
        limit: 15,
        page: page,
        province: userStore.user.province,
    };
    const res = await enrollLists(data);
    let list = res.lists.map((item) => {
        return {
            ...item,
            schoolMajor: `${item.school}--${item.major}`,
        };
    });
    tableData.value = list;
    tableTotal.value = res.total;
};
const enterExport = async (condition) => {
    let data = {
        ...condition,
        province: userStore.user.province,
    };
    const res = await enrollExport(data);
    flieDownload(res, "录取结果", "xlsx");
};
const tablePage = (val) => {
    list(enrolCondition.value, val);
};
onMounted(() => {
    list(enrolCondition.value);
});
</script>
<style lang="scss" scoped></style>
